<?php

namespace Xuan\Controller;

class BoxController extends CommonController {
     public function userAuto() {
        $name = I("get.term");
        $arr = array();
        $users =  M("user")->field("id,name")->where("name like '%" . $name . "%'")->limit(10)->select();
        foreach ($users as $k => $v) {
            $arr[$k]['id'] = $v['id'];
            $arr[$k]['label'] = $v['name'];
        }
        echo json_encode($arr);
    }
    public function joinShorts() {
        $lists = M("user")->where("is_shorts = 1")->select();
        $ids = ",";
        foreach ($lists as $v) {
            $ids .= $v['id'] . ",";
        }
        $this->assign("ids", $ids);
        $this->display();
    }

    public function shopLists() {
        import("Common.Org.PageAjax");
        $name = I("post.name");
        $sql = "1 = 1 ";
        if ($name != '') {
            $sql .= " AND name like '%" . $name . "%'";
        }
        $count = M('shop')->where($sql)->count();    //计算总数
        $Page = new Page($count, 5);
        $lists = M('shop')->where($sql)->limit($Page->firstRow . ',' . $Page->listRows)->order("id DESC")->select();
        $page = $Page->show();
        $this->assign("page", $page);
        $this->assign("lists", $lists);
        $this->display();
    }

    public function userLists() {
        import("Common.Org.PageAjax");
        $name = I("post.name");
        $sql = "1 = 1 ";
        if ($name != '') {
            $sql .= " AND name like '%" . $name . "%'";
        }
        $count = M('user')->where($sql)->count();    //计算总数
        $Page = new Page($count, 5);
        $lists = M('user')->where($sql)->limit($Page->firstRow . ',' . $Page->listRows)->order("id DESC")->select();
        $page = $Page->show();
        $this->assign("page", $page);
        $this->assign("lists", $lists);
        $this->display();
    }

}

?>
